package com.qidian.mes.md.controller;

import com.alibaba.fastjson2.JSON;
import com.qidian.mes.md.service.MaterialAndProductService;
import com.qidian.mes.md.vo.MaterialAndProductVO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: CoolPro
 * @Description: 产品物料数据接口
 * @Time: 2024-04-04 12:03
 **/

@RestController
@RequestMapping("/mat-pro")
@CrossOrigin
public class MaterialAndProductController {
    @Autowired
    private MaterialAndProductService materialAndProductService;

    /**
     * @param name     物料/产品名称
     * @param classify 分类名称
     * @param id       物料/产品编码
     * @Author: CoolPro
     * @Date: 4/4/2024
     * @Description: 根据分类名称，物料编码，物料名称查询产品和物料信息
     * @Name: query
     * @return: com.qidian.mes.util.pojo.QdResult
     */
    @GetMapping("/query")
    public QdResult query(
            @RequestParam(defaultValue = "") String name,
            @RequestParam(defaultValue = "-1") Integer classify,
            @RequestParam(defaultValue = "") String model,
            @RequestParam(defaultValue = "") String stockStatus,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "15") Integer limit) {
        return materialAndProductService.queryByParam(name, classify, model,stockStatus, page, limit,0);
    }

    @GetMapping("/query/material")
    public QdResult queryMaterial(@RequestParam(defaultValue = "") String name,
                                  @RequestParam(defaultValue = "-1") Integer classify,
                                  @RequestParam(defaultValue = "") String model,
                                  @RequestParam(defaultValue = "") String stockStatus,
                                  @RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "15") Integer limit){
        return materialAndProductService.queryByParam(name, classify, model,stockStatus, page, limit,1);

    }
    /**
     * @Author: CoolPro
     * @Date: 4/4/2024
     * @Description: 查询产品工单信息
     * @Name: queryOrder
     * @param id 产品ID
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @GetMapping("/query/order/{productId}")
    public QdResult queryOrder(@PathVariable("productId")String id){
        return materialAndProductService.queryByProductId(Integer.valueOf(id));
    }

    /**
     * @Author: CoolPro
     * @Date: 4/4/2024
     * @Description: 查询产品生产计划和完成状况信息
     * @Name: queryPlan
     * @param id 产品ID
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @GetMapping("/query/plan/{productId}")
    public QdResult queryPlan(@PathVariable("productId")Integer id){
        return materialAndProductService.queryPlannedAndCompletionByProductId(Integer.valueOf(id));
    }

    /**
     * @Author: CoolPro
     * @Date: 4/4/2024
     * @Description: 更新物料/产品的状态
     * @Name: updateStatus
     * @param id 物料/产品ID
     * @param status 状态
     * @param category 物料/产品分类
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @GetMapping("/update/status/{id}/{status}/{category}")
    public QdResult updateStatus(@PathVariable("id")Integer id,@PathVariable("status")String status,@PathVariable("category")Integer category){
        return materialAndProductService.updateMaterialAndProductStatus(id,status,category);
    }

    /**
     * @Author: CoolPro
     * @Date: 4/4/2024
     * @Description: 更新物料/产品的库存
     * @Name: updateInventory
     * @param id 物料/产品ID
     * @param inventory 阈值
     * @param category 物料/产品分类
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @GetMapping("/update/inventory/{id}/{inventory}/{category}")
    public QdResult updateInventory(@PathVariable("id")Integer id,@PathVariable("inventory")Integer inventory,@PathVariable("category")Integer category){
        return materialAndProductService.updateMaterialAndProductInventory(id,inventory,category);
    }

    /**
     * @Author: CoolPro
     * @Date: 6/4/2024
     * @Description:  修改产品物料分类信息
     * @Name: updateClassify
     * @param id 产品/物料ID
     * @param classifyId 分类ID
     * @param category 区分是产品还是物料
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @GetMapping("/update/classify/{id}/{classifyId}/{category}")
    public QdResult updateClassify(@PathVariable("id")Integer id,@PathVariable("classifyId")Integer classifyId,@PathVariable("category")Integer category){
        return materialAndProductService.updateMaterialAndProductClassify(id,classifyId,category);
    }

    /**
     * @Author: CoolPro
     * @Date: 6/4/2024
     * @Description:  添加产品物料信息
     * @Name: addMaterialAndProduct
     * @param data 产品/物料信息
     * @param category 区分是产品还是物料
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @PostMapping("/add/{category}")
    public QdResult addMaterialAndProduct(@RequestBody String data, @PathVariable Integer category){
        return materialAndProductService.addMaterialAndProduct(data,category);
    }


    /**
     * @Author: CoolPro
     * @Date: 7/4/2024
     * @Description: 修改产品物料信息
     * @Name: updateMaterialAndProduct
     * @param data
     * @param category
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @PutMapping("/update/{category}")
    public QdResult updateMaterialAndProduct(@RequestBody String data, @PathVariable Integer category){
        return materialAndProductService.updateMaterialAndProduct(data,category);
    }

}
